package com.quickask.entity;

import com.quickask.operate.data.RandomCode;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * Created by NaSa on 2015/9/23.
 */
@Entity
@Table(name = "asknow_collection", schema = "", catalog = "quickask")
@org.hibernate.annotations.Cache(usage= CacheConcurrencyStrategy.READ_WRITE, region = "com.quickask.entity.AsknowCollectionEntity")
public class AsknowCollectionEntity implements Serializable {
    private int collectedId;  //收藏记录的主键
    private Integer userId;  //用户id
    private Integer questionId;  //被收藏的问题
    private Timestamp collectedTime;  //收藏时间
    private Byte collectionIsAlive;  //收藏是否存在(0不存在,1存在)

    public AsknowCollectionEntity() {
        this.collectedTime = new RandomCode().generateCurrentTimestamp();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "collectedId", nullable = false, insertable = true, updatable = true)
    public int getCollectedId() {
        return collectedId;
    }

    public void setCollectedId(int collectedId) {
        this.collectedId = collectedId;
    }


    @Id
    @Column(name = "userId", nullable = false, insertable = true, updatable = true)
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Id
    @Column(name = "questionId", nullable = true, insertable = true, updatable = true)
    public Integer getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Integer questionId) {
        this.questionId = questionId;
    }

    @Basic
    @Column(name = "collectedTime", nullable = true, insertable = true, updatable = true)
    public Timestamp getCollectedTime() {
        return collectedTime;
    }

    public void setCollectedTime(Timestamp collectedTime) {
        this.collectedTime = collectedTime;
    }

    @Basic
    @Column(name = "collectionIsAlive", nullable = false, insertable = true, updatable = true)
    public Byte getCollectionIsAlive() {
        return collectionIsAlive;
    }

    public void setCollectionIsAlive(Byte collectionIsAlive) {
        this.collectionIsAlive = collectionIsAlive;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AsknowCollectionEntity)) return false;

        AsknowCollectionEntity that = (AsknowCollectionEntity) o;

        if (collectedId != that.collectedId) return false;
        if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false;
        if (questionId != null ? !questionId.equals(that.questionId) : that.questionId != null) return false;
        if (collectedTime != null ? !collectedTime.equals(that.collectedTime) : that.collectedTime != null)
            return false;
        return !(collectionIsAlive != null ? !collectionIsAlive.equals(that.collectionIsAlive) : that.collectionIsAlive != null);

    }

    @Override
    public int hashCode() {
        int result = collectedId;
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (questionId != null ? questionId.hashCode() : 0);
        result = 31 * result + (collectedTime != null ? collectedTime.hashCode() : 0);
        result = 31 * result + (collectionIsAlive != null ? collectionIsAlive.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "AsknowCollectionEntity{" +
                "collectedId=" + collectedId +
                ", userId=" + userId +
                ", questionId=" + questionId +
                ", collectedTime=" + collectedTime +
                ", collectionIsAlive=" + collectionIsAlive +
                '}';
    }
}
